package com.controller.share;

import com.entity.Answer;
import com.service.share.ExcelService;
import com.util.Util;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class ExcelController {



    @Autowired
    ExcelService excelService;

    /**
     * Excel模板下载
     */
    @GetMapping("public/downexcel")
    public Object downloadExcel(HttpServletRequest request, HttpServletResponse response,Integer patientID,String name) {
        Answer answer = (Answer) Util.fileDownload(response, request, patientID,name);
        return answer;
    }

    /**
     * Excel文件上传
     */
    @PostMapping("uploadExcel")
    public Object uploadExcel(HttpServletRequest request, List<MultipartFile> excel, int patientID) {
        System.out.println(patientID + " 1 " + excel);

        return   excelService.addExcel(excel,patientID);
    }

//    /**
//     * 读取excel
//     *
//     * @return
//     */
//    @GetMapping("viewexcel")
//    public Object viewTable(int patientID) {
//        return excelService.viewExcel(path + excelPath + patientID + "/MakeModel.xlsx");
//    }

    /**
     * 修病例详情的负文本编辑
     * patientID
     * key
     * value
     *
     */
    @PostMapping("updataNegativeText")
    public Object updataNegativeText(@RequestBody String data){
        JSONObject json = JSONObject.fromObject(data);
        Integer patientID = json.getInt("patientID");
        String  key = json.getString("key");
        String value = json.getString("value");
        return   excelService.updataNegativeText(patientID,key,value);
    }
}
